<?php

/**
 * This is the model class for table "book".
 *
 * The followings are the available columns in table 'book':
 * @property integer $id_book
 * @property integer $id_book_category
 * @property string $title
 * @property string $introtext
 * @property string $image
 * @property integer $published_price
 * @property integer $sale_price
 * @property string $year_released
 * @property string $date_upload
 * @property string $date_modified
 * @property integer $id_user_upload
 */
class Book extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Book the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'book';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id_book_category, title, introtext, id_user_upload', 'required'),
			array('id_book_category, published_price, sale_price, id_user_upload', 'numerical', 'integerOnly'=>true),
			array('title', 'length', 'max'=>1000),
			array('image', 'length', 'max'=>255),
			array('year_released, date_upload, date_modified', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id_book, id_book_category, title, introtext, image, published_price, sale_price, year_released, date_upload, date_modified, id_user_upload', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_book' => 'Id Book',
			'id_book_category' => 'Id Book Category',
			'title' => 'Title',
			'introtext' => 'Introtext',
			'image' => 'Image',
			'published_price' => 'Published Price',
			'sale_price' => 'Sale Price',
			'year_released' => 'Year Released',
			'date_upload' => 'Date Upload',
			'date_modified' => 'Date Modified',
			'id_user_upload' => 'Id User Upload',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id_book',$this->id_book);
		$criteria->compare('id_book_category',$this->id_book_category);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('introtext',$this->introtext,true);
		$criteria->compare('image',$this->image,true);
		$criteria->compare('published_price',$this->published_price);
		$criteria->compare('sale_price',$this->sale_price);
		$criteria->compare('year_released',$this->year_released,true);
		$criteria->compare('date_upload',$this->date_upload,true);
		$criteria->compare('date_modified',$this->date_modified,true);
		$criteria->compare('id_user_upload',$this->id_user_upload);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}